<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <button @click="fn">用户</button>
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>

    const router = new VueRouter({
      // 指定路由规则
      routes: [
        {
          path: '/user', component: {
            template: `<h1>用户页面</h1>`
          }
        }
      ]
    })

    new Vue({
      el: '#app',
      router,
      methods: {
        fn () {
          // 编程式导航
          this.$router.push('/user')
        }
      }
    })
  </script>
</body>

</html>